﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SIPO.Web.Support;
using SIPO.Library;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.Enum;
using SIPO.Library.Interfaces;
using SIPO.Library.DataAccess.Transaction;
using System.Configuration;
using System.Data;
using Microsoft.Reporting.WebForms;
namespace SIPO.Web.lists.Report

{
    public partial class rptVoucherPrint : BasePage
    {
        recBillingRepo recBillingDal = new recBillingRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        protected override void OnLoad(EventArgs e)
        {
            if (!IsPostBack)
            {

              //  DateTime? dPeriodeAwal = Context.Request.Params["id"].Equals(string.Empty) ? (DateTime?)null : Helper.FormatDate(Context.Request.Params["PeriodeAwal"], Helper.Culture.Indonesian);
              ////  DateTime? dPeriodeAkhir = Context.Request.Params["periodeAkhir"].Equals(string.Empty) ? (DateTime?)null : Helper.FormatDate(Context.Request.Params["PeriodeAkhir"], Helper.Culture.Indonesian);
              //  string sPeriodeAwal = dPeriodeAwal == null ? string.Empty : string.Format("{0:yyyy-MM-dd}", dPeriodeAwal);
              //  string sPeriodeAkhir = dPeriodeAkhir == null ? string.Empty : string.Format("{0:yyyy-MM-dd}", dPeriodeAkhir);

                string id = Context.Request.Params["id"];
                string parameters = string.Empty;
              try{

                  parameters += "where transactions.recBilling.BillingNo ='" + id+"'";
                  DataTable dt = recBillingDal.GetPrintVoucher(parameters);
                  rsViewer.Reset();
                  rsViewer.LocalReport.ReportPath = Server.MapPath("~/reportviewer/Transaction/rptVoucher.rdlc");
                  ReportDataSource rds = new ReportDataSource();
                  rds.Name = "DataSet1";
                  rds.Value = dt;

                  rsViewer.LocalReport.DataSources.Clear();
                  rsViewer.LocalReport.DataSources.Add(rds);
                  rsViewer.LocalReport.Refresh();

              }catch(Exception ex)
              {
                  throw (ex);
              }
              
            }
        }
    }
}